package com.five.controller;

import com.five.dto.IdRequest;
import com.five.pojo.Novel;
import com.five.result.Result;
import com.five.service.NovelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/novel")
public class NovelController {
    @Autowired
    private NovelService novelService;

    /**
     * 根据作者id获取作者所有书籍
     */
    @PostMapping("/author/books")
    public Result<List<Novel>> getAuthorBooks(@RequestBody IdRequest request) {
        try {
            List<Novel> data = novelService.getAuthorBooks(request.getAuthorId());
            return Result.success(data);
        } catch (Exception e) {
            return Result.error("获取作者书籍失败: " + e.getMessage());
        }

    }
}
